import request from '../../utils/request';
import { LoginParams, RegisterParams, LoginResult, UserInfo } from '../../models/user';
import { ApiResponse } from '../../models/common';

/**
 * 用户登录
 * @param params 登录参数
 * @returns Promise<LoginResult['data']>
 */
export const login = async (params: LoginParams) => {
  return request.post<LoginResult['data']>('/user/login', params);
};

/**
 * 用户注册
 * @param params 注册参数
 * @returns Promise<boolean>
 */
export const register = async (params: RegisterParams) => {
  return request.post<boolean>('/user/register', params);
};

/**
 * 获取当前用户信息
 * @returns Promise<UserInfo>
 */
export const getUserInfo = async () => {
  return request.get<UserInfo>('/user/info');
};

/**
 * 获取当前管理员信息
 * @returns Promise<UserInfo>
 */
export const getAdminInfo = async () => {
  return request.get<UserInfo>('/user/3');
};

/**
 * 用户登出
 * @returns Promise<boolean>
 */
export const logout = async () => {
  return request.post<boolean>('/user/logout');
};